package com.example.common;

import java.util.List;

public class Pagination<T> {
    //当前页
    public Integer pageNo;
    //每页显示条数
    public Integer pageSize;
    //总页数，分了多少页
    public Integer pageTotal;
    //查询的总记录数
    public Integer count;
    //开始记录数
    public Integer startNum;
    //结束记录数
    public Integer endNum;
    //查询出来的list集合
    public List<T> list;

    /***        oracle分页思想
     * pageNo  pageSize startNum endNum
     * 1         10       0       11
     * 2         10       10      21
     *
     * startNum = (pageNo-1)*pageSize
     * endNum   =  pageNo*pageSize + 1
     *
     * pageSize  count  pageTotal
     *
     * 10         0       1
     * 100        10      10
     * 99         10      10
     *
     * 条件：
     * count/pageSize == 0 || count%pageSize!=0     count/pageSize+1
     * count%pageSize == 0                          count/pageSize
     * *******/
    public Integer getPageNo() {
        return pageNo;
    }
    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }
    public Integer getPageSize() {
        return pageSize;
    }
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
    public Integer getPageTotal() {
        return pageTotal;
    }

    public Integer getCount() {
        return count;
    }

    public Integer getStartNum() {

        return startNum;
    }

    public Integer getEndNum() {
        return endNum;
    }

    public List<T> getList() {
        return list;
    }
    public void setList(List<T> list) {
        this.list = list;
    }

    public Pagination(Integer pageNo, Integer pageSize, Integer count){
        this.pageNo = pageNo;
        this.count = count;
        this.pageSize = pageSize;

        if(pageSize != null && pageSize > 0){
            this.pageTotal = count/pageSize;
            if(pageTotal == 0 || (count%pageSize != 0)){
                this.pageTotal = pageTotal + 1;
            }

            this.startNum = (pageNo-1)*pageSize;
            this.endNum = pageNo*pageSize + 1;
        }
    }
}
